var vm = new Vue({
	el:'#app',
	data:{
		money:[],//每个红包的随机金额
//		amount:5000,//总金额
//		max:80,//红包最大值
//		min:20,//红包最小值
		egg_num:100,//金蛋数量
		egg_numnow:0,//金蛋剩余量
		egg_list:["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],//金蛋列
		bonus_show:false,//红包弹窗
		bonus_num:0,//红包弹窗金额
		set_show:true,//设置弹窗
		num_show:true,//设置金蛋数弹窗
		money_show:false,//设置金额弹窗
		egg_moneyList:[],//金额列表
		ranking_list:[
		{company:"",money:2688},
		{company:"",money:1288},
		{company:"",money:888},
		{company:"",money:666},
		{company:"",money:500},
		],//排行榜列表
		activity_rules:"",//活动规则
//		ranking_input:"",//排行榜输入框内容
//		ranking_choose:0,//被选中的人
		
	},
	created(){
		
	},
	mounted(){
//		this.ATM();
	},
	computed:{
		remain(){
			return this.egg_num-this.egg_numnow;
		},
		list(){
			return this.egg_num/10
		}
	},
	watch:{
		egg_moneyList:{
			handler(newval,oldval){
				let sun = 0;
				for(let i=0;i<this.egg_moneyList.length;i++){
					if(this.egg_moneyList[i].num<0){
						this.egg_moneyList[i].num = 0;
					}
					sun = Number(this.egg_moneyList[i].num) + sun;
				}
				this.egg_numnow = sun 
			},
			deep:true
		}
	},
	methods:{
//		ATM(){
//			let one = 0;
//			let num = 0
//			for(let i = 0;i<this.egg_num;i++){
//				one = Math.floor(Math.random()*10000)/100;
//				while(one>this.max||one<this.min){
//					one = Math.floor(Math.random()*10000)/100;
//				};
//				this.money[i] = one;
//				num = num + one;
//				if(num > this.amount){
//					this.money = [];
//					num = 0;
//					ATM();
//				}
//			}
//			console.log(this.money)
//		},
		eggClick(index,event){
			if(this.ranking_list.length > 0){
				if(event.target.childNodes.length==0){
					event.target.classList.add('vivify','shake');
					setTimeout(()=>{
						event.target.style.backgroundImage = "url(img/egg-po.png)"
						this.bonus_show = true;
						this.bonus_num = this.money[index];
						event.target.innerHTML=this.money[index];
					},1000)
				}
			}else{
				alert("没有人参加请先添加");
			}
			
		},
		addRanking(){
			if(this.ranking_input==""){
				return ;
			}
			let x = true;
			for(let i = 0;i<this.ranking_list.length;i++){
				if(this.ranking_list[i].company == this.ranking_input){
					this.ranking_list.splice(i,1)
					x = false;
				}
			}
			
			if(x){
				this.ranking_list.push({
					company:this.ranking_input,
					money:0.00,
				})
			}
			this.ranking_input = ""
		},
		rankingChoose(who){
			this.ranking_choose = who;
		},
//		sort(){
//			let medium = null;
//			for (var j = 0; j <= this.ranking_list.length-1; j++) {
//	            var flag = true;
//	            for (var i = 0; i <= this.ranking_list.length-1-j; i++) {
//		            if (this.ranking_list[i+1]&&this.ranking_list[i].money < this.ranking_list[i+1].money) {
//		                medium = this.ranking_list[i];
//		                this.ranking_list[i] = this.ranking_list[i+1];
//		                this.ranking_list[i+1] = medium;
//		                this.ranking_choose=i
//		                flag = false
//		            }
//	        }
//		        if (flag) {
//		            break
//		        }
//	        }
//		},
		start(){
			let sun = 0;
			for(let i=0;i<this.egg_moneyList.length;i++){
				sun = Number(this.egg_moneyList[i].num) + sun;
			}
			if(sun>this.egg_num){
				alert("你输入的金蛋数比你设置的金蛋数多");
			}else{
				for(let i = 0;i<this.egg_moneyList.length;i++){
					for(let j=0;j<this.egg_moneyList[i].num;j++){
						this.money.push(this.egg_moneyList[i].money)
					}
				}
				for(let i=0;i<this.egg_num-this.egg_numnow;i++){
					this.money.push(0)
				}
				this.money.sort(() => Math.random() - 0.5);
				this.set_show=false;
			}
		},
		addegg_moneyList(){
			this.egg_moneyList.push({num:0,money:0})
		},
	}
})
